
%\documentclass[letterpaper,12pt]{article}
%\usepackage[x11names,rgb]{xcolor}
%\usepackage{tikz}
%\usepackage{pgffor}
%\usetikzlibrary{shapes,arrows,trees,snakes,patterns}
%\usetikzlibrary{backgrounds}
%\usepackage{amsmath}
%\oddsidemargin 0in
%\evensidemargin 0in
%\topmargin 0in
%\headheight 0in
%\headsep 0in
%\textheight 9in
%\textwidth 6.5in
%\begin{document}
%\pagestyle{empty}
%\vspace*{\fill}
%\begin{center}
\documentclass{article}
 
\usepackage[pdftex,active,tightpage]{preview}
\usepackage{tikz}
\usetikzlibrary{snakes}
\usetikzlibrary{arrows}
\makeatletter
 
\begin{document}
\begin{preview}
	%%
	\begin{tikzpicture}[scale=1.0]
	
	\draw[very thin,color=gray,xstep=1, ystep=0.5] (-0.1,-0.1) grid (11, 5.5);
	%1cm spacing for x-axis and 0.5 cm spacing for y-axis
	\draw[->] (-0.2,0) -- (11.2, 0) node[right] {$n_p$};
	\draw[->] (0,-0.2) -- (0, 5.9) node[above] {seconds};
	
	%Draw the x-axis ticks now
	\foreach \pos/\label in {0.5/1, 1.5/2, 2.5/4, 3.5/8, 4.5/16, 5.5/32, 6.5/64, 7.5/128, 8.5/256, 9.5/512, 10.5/1024} {
	\draw (\pos,0) -- (\pos,-0.1) (\pos cm, -2.5ex) node [anchor=base,fill=white,inner sep=1pt]  {\scriptsize \label};
	}
	
	\newdimen\ysc
	
	\ysc=0.1 cm
	
	%Draw the y-axis ticks now...
	\foreach \label in {0, 5,...,55} {
	\draw (-2.5ex, \ysc*\label) node [anchor=base,fill=white,inner sep=1pt] {\scriptsize \label};
	}
	
	%Draw the table for the numbers.
	\foreach \ctry in {-2.5, -2, -1.5, -1.0} {
		\foreach \ctrx in {0, 1, ..., 10} {
			\draw[very thin,color=gray] (\ctrx cm, \ctry cm) rectangle +(1,0.5);
		}
	}
	
	%Draw the Legend now..
	\draw (-5.5,-1.0) rectangle +(5.5,0.5);
	\draw[fill=black] (-0.5,-1.0) rectangle +(0.5,0.5);
	\draw (-5, -0.75) node[right] {\scriptsize Construction};
	
	\draw (-5.5,-1.5) rectangle +(5.5,0.5);
	\draw[fill=black!75] (-0.5,-1.5) rectangle +(0.5,0.5);
	\draw (-5, -1.25) node[right] {\scriptsize Internal Balance};
	
	\draw (-5.5,-2.0) rectangle +(5.5,0.5);
	\draw[fill=black!50] (-0.5,-2.0) rectangle +(0.5,0.5);
	\draw (-5, -1.75) node[right] {\scriptsize Boundary Balance};
	
	\draw (-5.5,-2.5) rectangle +(5.5,0.5);
	\draw[fill=black!20] (-0.5,-2.5) rectangle +(0.5,0.5);
	\draw (-5, -2.25) node[right] {\scriptsize Communication for Balance};
	
	\newdimen\mypos
	
	%vala: Construction, valb: Internal Balance
	%valc: Boundary Balance vald: Communication for Balance
	\foreach \pos/\vala/\valb/\valc/\vald in { 
	 0 / 3.2  / 10.1 / 0.0  / 1.9 ,
	 1 / 8.1 / 13.96 / 0.0 / 2.4 ,
	 2 / 5.7 / 9.0 / 0.0 / 3.5 ,
	 3 / 4.4 / 10.6 / 0.0 / 2.5 ,
	 4 / 8.0 / 14.4 / 0.0 / 2.9 ,
	 5 / 5.8 / 9.3 / 0.0 / 4.1 ,
	 6 / 4.8 / 10.9 / 0.0 / 3.1 ,
	 7 / 8.0 / 14.7 / 0.0 / 3.9 ,
	 8 / 6.7 / 9.0 / 0.0 / 5.0 ,
	 9 / 6.4 / 6.3 / 0.0 / 5.0 ,
	 10 / 18 / 14 / 0.0 / 19 
	 }
	 { 
	
	\mypos=\pos cm
	
	%Filing the table below the plot...
	\advance \mypos by 0.5 cm
	
	\draw (\mypos, -0.75 cm) node {\tiny \vala};
	\draw (\mypos, -1.25 cm) node {\tiny \valb};
	\draw (\mypos, -1.75 cm) node {\tiny \valc};
	\draw (\mypos, -2.25 cm) node {\tiny \vald};
	
	%Width of the column=0.6 cm, 
	%Leave 0.2 cm gap on either side of the column
	\advance \mypos by -0.3 cm
	
	%Construction
	\draw[fill=black] (\mypos,0) rectangle +(0.6,\ysc*\vala);
	\path (\mypos, \ysc*\vala) coordinate (tmpA);
	
	%Internal Balance
	\draw[fill=black!75] (tmpA) rectangle +(0.6,\ysc*\valb);
	\path (tmpA) +(0, \ysc*\valb) coordinate (tmpB);
	
	%Boundary Balance
	\draw[fill=black!50] (tmpB) rectangle +(0.6,\ysc*\valc);
	\path (tmpB) +(0, \ysc*\valc) coordinate (tmpC);
	
	%Communication for Balance
	\draw[fill=black!20] (tmpC) rectangle +(0.6,\ysc*\vald);
	
	}
	
	\end{tikzpicture}%%
\end{preview}
\end{document}

%\end{center}
%\vspace*{\fill}
%\end{document}
